<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"
	trimDirectiveWhitespaces="true"%>
<%@page import="java.util.Date"%>
<%@ include file="../../admin.inc.jsp"%>

<link type="text/css" rel="stylesheet" href="${styleContextPath}/styles/ztree/css/zTreeStyle.css" />
<script type="text/javascript" src="${styleContextPath}/styles/ztree/js/jquery.ztree.all-3.5.js"></script>
<script type="text/javascript" language="javascript">
/**ztree的参数配置，setting主要是设置一些tree的属性，是本地数据源，还是远程，动画效果，是否含有复选框等等**/  
	var zTree;
    var setting = {
            view:{
                selectedMulti:true
            },
            check: {
				enable: true
			},
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                beforeDrag:beforeDrag,//用户禁止拖动节点
            }
        };
    var zNodes;
    $(document).ready(function(){
    	$.ajax({  
            async : false,  
            cache:false,  
            type: 'POST',  
            dataType : "json",  
            url: "${webContextPath}/admin/rolePermission/doModuleTree?roleId="+$('#roleId').val(),//请求的action路径  
            error: function () {//请求失败处理函数  
                alert('请求失败');  
            },  
            success:function(data){ //请求成功后处理函数。   
                zNodes = data;   //把后台封装好的简单Json格式赋给treeNodes  
            }  
        });
    	
        zTree = $.fn.zTree.init($("#moduleTree"), setting, zNodes);
    });
    function beforeDrag(treeId,treeNodes){
        return false;
    }
    function botton_onclick(){
    	var nodes = zTree.getCheckedNodes(true);
    	var nodeString = "";
    	if(nodes != null){
    		for ( var i = 0; i < nodes.length; i++) {
    			if(i==0){
    				nodeString = nodes[i].id;
    			} else {
    				nodeString += "," + nodes[i].id;
    			}
			}
    	}
    	var roleId = $('#roleId').val();
    	if(nodeString == ''){
    		alert("请对角色进行授权");
    		return;
    	}
    	$('#save').attr('href','${webContextPath}/admin/rolePermission/insertRolePermission?roleId='+roleId +'&permission=' + nodeString );//通向后台的目标链接
		$('#save').click();
    }
    </script>
	<input type="hidden" name="roleId" id="roleId" value="${roleId}" />
	<a id="save"  title="保存角色权限" target="ajaxTodo"  href="${webContextPath}/admin/rolePremission/insertRolePremission?roleId=${item.id}"  hidden="true">保存角色权限</a>
    <style type="text/css">
.leftside{ background: #E6E6E6; float: left; height: 100%; width: 280px; margin: 0px; overflow-y:auto; } 
.rightside{ background: white; height: 100%; width:100%; align:right;}
	</style>
<body>
    <div class="rightside">
    	<table><tr><td><button onclick="botton_onclick()">保存角色权限</button></td></tr></table>
		<ul id="moduleTree" class="ztree"></ul>
	</div>
</body>